<template>
  <div class="home-container">
    <el-row :gutter="15" class="home-card-one mb15">
      <el-col
          :xs="24"
          :sm="12"
          :md="12"
          :lg="6"
          :xl="6"
          v-for="(v, k) in homeOne"
          :key="k"
          :class="{ 'home-media home-media-lg': k > 1, 'home-media-sm': k === 1 }"
      >
        <div class="home-card-item flex">
          <div class="flex-margin flex w100" :class="` home-one-animation${k}`">
            <div class="flex-auto">
              <span class="font30">{{ v.num1 }}</span>
              <span class="ml5 font16" :style="{ color: v.color1 }">{{ v.num2 }}%</span>
              <div class="mt10">{{ v.num3 }}</div>
            </div>
            <div class="home-card-item-icon flex" :style="{ background: `var(${v.color2})` }">
              <i class="iconfont flex-margin font32" :class="v.num4" :style="{ color: `var(${v.color3})` }"></i>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
    <el-row :gutter="15" class="home-card-two mb15">
      <el-col :xs="24" :sm="14" :md="14" :lg="16" :xl="16">
        <div class="home-card-item">
          <div style="height: 100%" ref="homeBarRef"></div>
        </div>
      </el-col>
      <el-col :xs="24" :sm="10" :md="10" :lg="8" :xl="8" class="home-media">
        <div class="home-card-item">
          <div style="height: 100%" ref="homePieRef"></div>
        </div>
      </el-col>
    </el-row>



    <el-row :gutter="15" class="home-card-three">


      <el-col :xs="24" :sm="10" :md="10" :lg="8" :xl="8" class="home-media">
        <div class="home-card-item">
          <div style="height: 100%" ref="homeBar1Ref"></div>
        </div>
      </el-col>


      <el-col :xs="24" :sm="14" :md="14" :lg="16" :xl="16" class="home-media">
        <div class="home-card-item">
          <div style="height: 100%" ref="homeLineRef"></div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script lang="ts">
import { toRefs, reactive, defineComponent, onMounted, ref, watch, nextTick, onActivated } from 'vue';
import * as echarts from 'echarts';
import 'echarts-wordcloud';
import { useStore } from '/@/store/index';

let global: any = {
  homeChartOne: null,
  homeChartTwo: null,
  homeCharThree: null,
  homeChartFour: null,
  dispose: [null, '', undefined],
};

export default defineComponent({
  name: 'home',
  setup() {
    const homeLineRef = ref();
    const homePieRef = ref();
    const homeBarRef = ref();
    const homeBar1Ref =ref();
    const store = useStore();
    const state = reactive({
      homeOne: [
        {
          num1: '125,12',
          num2: '-12.32',
          num3: '订单统计信息',
          num4: 'icon-putong',
          color1: '#FF6462',
          color2: '--next-color-primary-lighter',
          color3: '--el-color-primary',
        },
        {
          num1: '653,33',
          num2: '+42.32',
          num3: '月度计划信息',
          num4: 'icon-ditu',
          color1: '#6690F9',
          color2: '--el-color-success-lighter',
          color3: '--el-color-success',
        },
        {
          num1: '125,65',
          num2: '+17.32',
          num3: '年度计划信息',
          num4: 'icon-zaosheng',
          color1: '#6690F9',
          color2: '--el-color-warning-lighter',
          color3: '--el-color-warning',
        },
        {
          num1: '520,43',
          num2: '-10.01',
          num3: '访问统计信息',
          num4: 'icon-skin',
          color1: '#FF6462',
          color2: '--el-color-danger-lighter',
          color3: '--el-color-danger',
        },
      ],
      homeThree: [
        {
          icon: 'iconfont icon-yangan',
          label: '浅粉红',
          value: '2.1%OBS/M',
          iconColor: '#F72B3F',
        },
        {
          icon: 'iconfont icon-wendu',
          label: '深红(猩红)',
          value: '30℃',
          iconColor: '#91BFF8',
        },
        {
          icon: 'iconfont icon-shidu',
          label: '淡紫红',
          value: '57%RH',
          iconColor: '#88D565',
        },
        {
          icon: 'iconfont icon-shidu',
          label: '弱紫罗兰红',
          value: '107w',
          iconColor: '#88D565',
        },
        {
          icon: 'iconfont icon-zaosheng',
          label: '中紫罗兰红',
          value: '57DB',
          iconColor: '#FBD4A0',
        },
        {
          icon: 'iconfont icon-zaosheng',
          label: '紫罗兰',
          value: '57PV',
          iconColor: '#FBD4A0',
        },
        {
          icon: 'iconfont icon-zaosheng',
          label: '暗紫罗兰',
          value: '517Cpd',
          iconColor: '#FBD4A0',
        },
        {
          icon: 'iconfont icon-zaosheng',
          label: '幽灵白',
          value: '12kg',
          iconColor: '#FBD4A0',
        },
        {
          icon: 'iconfont icon-zaosheng',
          label: '海军蓝',
          value: '64fm',
          iconColor: '#FBD4A0',
        },
      ],
      myCharts: [],
      charts: {
        theme: '',
        bgColor: '',
        color: '#303133',
      },
    });
    // 折线图
    const initLineChart = () => {
      if (!global.dispose.some((b: any) => b === global.homeChartOne)) global.homeChartOne.dispose();
      global.homeChartOne = <any>echarts.init(homeLineRef.value, state.charts.theme);
      const option = {
        backgroundColor: state.charts.bgColor,
        title: {
          text: '政策补贴额度',
          x: 'left',
          textStyle: { fontSize: '15', color: state.charts.color },
        },
        grid: { top: 70, right: 20, bottom: 30, left: 30 },
        tooltip: { trigger: 'axis' },
        legend: { data: ['预购队列', '最新成交价'], right: 0 },
        xAxis: {
          data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
        },
        yAxis: [
          {
            type: 'value',
            name: '价格',
            splitLine: { show: true, lineStyle: { type: 'dashed', color: '#f5f5f5' } },
          },
        ],
        series: [
          {
            name: '预购队列',
            type: 'line',
            symbolSize: 6,
            symbol: 'circle',
            smooth: true,
            data: [0, 41.1, 30.4, 65.1, 53.3, 53.3, 53.3, 41.1, 30.4, 65.1, 53.3, 10],
            lineStyle: { color: '#fe9a8b' },
            itemStyle: { color: '#fe9a8b', borderColor: '#fe9a8b' },
            areaStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: '#fe9a8bb3' },
                { offset: 1, color: '#fe9a8b03' },
              ]),
            },
          },
          {
            name: '最新成交价',
            type: 'line',
            symbolSize: 6,
            symbol: 'circle',
            smooth: true,
            data: [0, 24.1, 7.2, 15.5, 42.4, 42.4, 42.4, 24.1, 7.2, 15.5, 42.4, 0],
            lineStyle: { color: '#9E87FF' },
            itemStyle: { color: '#9E87FF', borderColor: '#9E87FF' },
            areaStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: '#9E87FFb3' },
                { offset: 1, color: '#9E87FF03' },
              ]),
            },
            emphasis: {
              itemStyle: {
                color: {
                  type: 'radial',
                  x: 0.5,
                  y: 0.5,
                  r: 0.5,
                  colorStops: [
                    { offset: 0, color: '#9E87FF' },
                    { offset: 0.4, color: '#9E87FF' },
                    { offset: 0.5, color: '#fff' },
                    { offset: 0.7, color: '#fff' },
                    { offset: 0.8, color: '#fff' },
                    { offset: 1, color: '#fff' },
                  ],
                },
                borderColor: '#9E87FF',
                borderWidth: 2,
              },
            },
          },
        ],
      };
      (<any>global.homeChartOne).setOption(option);
      (<any>state.myCharts).push(global.homeChartOne);
    };
    // 饼图
    const initWorldcouldChart = () => {
      if (!global.dispose.some((b: any) => b === global.homeChartTwo)) global.homeChartTwo.dispose();
      global.homeChartTwo = <any>echarts.init(homePieRef.value, state.charts.theme);
      const maskImage=new Image();
      maskImage.src='' ;
      const option = {
        grid: {
          top: 15,
          right: 15,
          bottom: 20,
          left: 30,
        },
        tooltip: {},
        series: [
          {
            type: 'wordCloud',
            sizeRange: [12, 40],
            rotationRange: [0, 0],
            rotationStep: 45,
            gridSize: Math.random() * 20 + 5,
            shape: 'circle',
            width: '100%',
            height: '100%',
            maskImage: maskImage,
            textStyle: {
              fontFamily: 'sans-serif',
              fontWeight: 'bold',
              color: function () {
                return `rgb(${[Math.round(Math.random() * 160), Math.round(Math.random() * 160), Math.round(Math.random() * 160)].join(',')})`;
              },
            },
            data: [
              { name: 'vue-next-admin', value: 520 },
              { name: 'lyt', value: 520 },
              { name: 'next-admin', value: 500 },
              { name: '更名', value: 420 },
              { name: '智慧农业', value: 520 },
              { name: '男神', value: 2.64 },
              { name: '好身材', value: 4.03 },
              { name: '校草', value: 24.95 },
              { name: '酷', value: 4.04 },
              { name: '时尚', value: 5.27 },
              { name: '阳光活力', value: 5.8 },
              { name: '初恋', value: 3.09 },
              { name: '英俊潇洒', value: 24.71 },
              { name: '霸气', value: 6.33 },
              { name: '腼腆', value: 2.55 },
              { name: '蠢萌', value: 3.88 },
              { name: 'vue-next-admin', value: 520 },
              { name: 'lyt', value: 520 },
              { name: 'next-admin', value: 500 },
              { name: '更名', value: 420 },
              { name: '智慧农业', value: 520 },
              { name: '男神', value: 2.64 },
              { name: '好身材', value: 4.03 },
              { name: '校草', value: 24.95 },
              { name: '酷', value: 4.04 },
              { name: '时尚', value: 5.27 },
              { name: '阳光活力', value: 5.8 },
              { name: '初恋', value: 3.09 },
              { name: '英俊潇洒', value: 24.71 },
              { name: '霸气', value: 6.33 },
              { name: '腼腆', value: 2.55 },
              { name: '蠢萌', value: 3.88 },
              { name: '青春', value: 8.04 },
              { name: '网红', value: 5.87 },
              { name: '萌', value: 6.97 },
              { name: '认真', value: 2.53 },
              { name: '古典', value: 2.49 },
              { name: '温柔', value: 3.91 },
              { name: '有个性', value: 3.25 },
              { name: '可爱', value: 9.93 },
              { name: '幽默诙谐', value: 3.65 },
            ],
          },
        ],
      };
      (<any>global.homeChartTwo).setOption(option);
      (<any>state.myCharts).push(global.homeChartTwo);
    };
    // 柱状图
    const initBarChart = () => {
      if (!global.dispose.some((b: any) => b === global.homeCharThree)) global.homeCharThree.dispose();
      global.homeCharThree = <any>echarts.init(homeBarRef.value, state.charts.theme);
      const option = {
        backgroundColor: state.charts.bgColor,
        title: {
          text: '地热开发利用',
          x: 'left',
          textStyle: { fontSize: '15', color: state.charts.color },
        },
        tooltip: { trigger: 'axis' },
        legend: { data: ['供温', '回温', '压力值(Mpa)'], right: 0 },
        grid: { top: 70, right: 80, bottom: 30, left: 80 },
        xAxis: [
          {
            type: 'category',
            data: ['1km', '2km', '3km', '4km', '5km', '6km'],
            boundaryGap: true,
            axisTick: { show: false },
          },
        ],
        yAxis: [
          {
            name: '供回温度(℃）',
            nameLocation: 'middle',
            nameTextStyle: { padding: [3, 4, 50, 6] },
            splitLine: { show: true, lineStyle: { type: 'dashed', color: '#f5f5f5' } },
            axisLine: { show: false },
            axisTick: { show: false },
            axisLabel: { color: state.charts.color, formatter: '{value} ' },
          },
          {
            name: '压力值(Mpa)',
            nameLocation: 'middle',
            nameTextStyle: { padding: [50, 4, 5, 6] },
            splitLine: { show: false },
            axisLine: { show: false },
            axisTick: { show: false },
            axisLabel: { color: state.charts.color, formatter: '{value} ' },
          },
        ],
        series: [
          {
            name: '供温',
            type: 'line',
            smooth: true,
            showSymbol: true,
            // 矢量画五角星
            symbol: 'path://M150 0 L80 175 L250 75 L50 75 L220 175 Z',
            symbolSize: 12,
            yAxisIndex: 0,
            areaStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: 'rgba(250,180,101,0.3)' },
                { offset: 1, color: 'rgba(250,180,101,0)' },
              ]),
              shadowColor: 'rgba(250,180,101,0.2)',
              shadowBlur: 20,
            },
            itemStyle: { color: '#FF8000' },
            // data中可以使用对象，value代表相应的值，另外可加入自定义的属性
            data: [
              { value: 1, stationName: 's1' },
              { value: 3, stationName: 's2' },
              { value: 4, stationName: 's3' },
              { value: 9, stationName: 's4' },
              { value: 3, stationName: 's5' },
              { value: 2, stationName: 's6' },
            ],
          },
          {
            name: '回温',
            type: 'line',
            smooth: true,
            showSymbol: true,
            symbol: 'emptyCircle',
            symbolSize: 12,
            yAxisIndex: 0,
            areaStyle: {
              color: new echarts.graphic.LinearGradient(
                  0,
                  0,
                  0,
                  1,
                  [
                    { offset: 0, color: 'rgba(199, 237, 250,0.5)' },
                    { offset: 1, color: 'rgba(199, 237, 250,0.2)' },
                  ],
                  false
              ),
            },
            itemStyle: {
              color: '#3bbc86',
            },
            data: [
              { value: 31, stationName: 's1' },
              { value: 36, stationName: 's2' },
              { value: 54, stationName: 's3' },
              { value: 24, stationName: 's4' },
              { value: 73, stationName: 's5' },
              { value: 22, stationName: 's6' },
            ],
          },
          {
            name: '压力值(Mpa)',
            type: 'bar',
            barWidth: 30,
            yAxisIndex: 1,
            itemStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: 'rgba(108,80,243,0.3)' },
                { offset: 1, color: 'rgba(108,80,243,0)' },
              ]),
              //柱状图圆角
              borderRadius: [30, 30, 0, 0],
            },
            data: [
              { value: 11, stationName: 's1' },
              { value: 34, stationName: 's2' },
              { value: 54, stationName: 's3' },
              { value: 39, stationName: 's4' },
              { value: 63, stationName: 's5' },
              { value: 24, stationName: 's6' },
            ],
          },
        ],
      };
      (<any>global.homeCharThree).setOption(option);
      (<any>state.myCharts).push(global.homeCharThree);
    };

    // 柱状图
    const initBarChart1 = () => {
      if (!global.dispose.some((b: any) => b === global.homeChartFour)) global.homeChartFour.dispose();
      global.homeChartFour = <any>echarts.init(homeBar1Ref.value, state.charts.theme);
      const dateList = [
        ['2017-1-1', '初四'],
        ['2017-1-2', '初五'],
        ['2017-1-3', '初六'],
        ['2017-1-4', '初七'],
        ['2017-1-5', '初八', '小寒'],
        ['2017-1-6', '初九'],
        ['2017-1-7', '初十'],
        ['2017-1-8', '十一'],
        ['2017-1-9', '十二'],
        ['2017-1-10', '十三'],
        ['2017-1-11', '十四'],
        ['2017-1-12', '十五'],
        ['2017-1-13', '十六'],
        ['2017-1-14', '十七'],
        ['2017-1-15', '十八'],
        ['2017-1-16', '十九'],
        ['2017-1-17', '二十'],
        ['2017-1-18', '廿一'],
        ['2017-1-19', '廿二'],
        ['2017-1-20', '廿三', '大寒'],
        ['2017-1-21', '廿四'],
        ['2017-1-22', '廿五'],
        ['2017-1-23', '廿六'],
        ['2017-1-24', '廿七'],
        ['2017-1-25', '廿八'],
        ['2017-1-26', '廿九'],
        ['2017-1-27', '三十'],
        ['2017-1-28', '正月'],
        ['2017-1-29', '初二'],
        ['2017-1-30', '初三'],
        ['2017-1-31', '初四'],
        ['2017-2-1', '初五'],
        ['2017-2-2', '初六'],
        ['2017-2-3', '初七', '立春'],
        ['2017-2-4', '初八'],
        ['2017-2-5', '初九'],
        ['2017-2-6', '初十'],
        ['2017-2-7', '十一'],
        ['2017-2-8', '十二'],
        ['2017-2-9', '十三'],
        ['2017-2-10', '十四'],
        ['2017-2-11', '十五'],
        ['2017-2-12', '十六'],
        ['2017-2-13', '十七'],
        ['2017-2-14', '十八'],
        ['2017-2-15', '十九'],
        ['2017-2-16', '二十'],
        ['2017-2-17', '廿一'],
        ['2017-2-18', '廿二', '雨水'],
        ['2017-2-19', '廿三'],
        ['2017-2-20', '廿四'],
        ['2017-2-21', '廿五'],
        ['2017-2-22', '廿六'],
        ['2017-2-23', '廿七'],
        ['2017-2-24', '廿八'],
        ['2017-2-25', '廿九'],
        ['2017-2-26', '二月'],
        ['2017-2-27', '初二'],
        ['2017-2-28', '初三'],
        ['2017-3-1', '初四'],
        ['2017-3-2', '初五'],
        ['2017-3-3', '初六'],
        ['2017-3-4', '初七'],
        ['2017-3-5', '初八', '驚蟄'],
        ['2017-3-6', '初九'],
        ['2017-3-7', '初十'],
        ['2017-3-8', '十一'],
        ['2017-3-9', '十二'],
        ['2017-3-10', '十三'],
        ['2017-3-11', '十四'],
        ['2017-3-12', '十五'],
        ['2017-3-13', '十六'],
        ['2017-3-14', '十七'],
        ['2017-3-15', '十八'],
        ['2017-3-16', '十九'],
        ['2017-3-17', '二十'],
        ['2017-3-18', '廿一'],
        ['2017-3-19', '廿二'],
        ['2017-3-20', '廿三', '春分'],
        ['2017-3-21', '廿四'],
        ['2017-3-22', '廿五'],
        ['2017-3-23', '廿六'],
        ['2017-3-24', '廿七'],
        ['2017-3-25', '廿八'],
        ['2017-3-26', '廿九'],
        ['2017-3-27', '三十'],
        ['2017-3-28', '三月'],
        ['2017-3-29', '初二'],
        ['2017-3-30', '初三'],
        ['2017-3-31', '初四'],
        ['2017-4-1', '初五'],
        ['2017-4-2', '初六'],
        ['2017-4-3', '初七'],
        ['2017-4-4', '初八', '清明'],
        ['2017-4-5', '初九'],
        ['2017-4-6', '初十'],
        ['2017-4-7', '十一'],
        ['2017-4-8', '十二'],
        ['2017-4-9', '十三'],
        ['2017-4-10', '十四'],
        ['2017-4-11', '十五'],
        ['2017-4-12', '十六'],
        ['2017-4-13', '十七'],
        ['2017-4-14', '十八'],
        ['2017-4-15', '十九'],
        ['2017-4-16', '二十'],
        ['2017-4-17', '廿一'],
        ['2017-4-18', '廿二'],
        ['2017-4-19', '廿三'],
        ['2017-4-20', '廿四', '穀雨'],
        ['2017-4-21', '廿五'],
        ['2017-4-22', '廿六'],
        ['2017-4-23', '廿七'],
        ['2017-4-24', '廿八'],
        ['2017-4-25', '廿九'],
        ['2017-4-26', '四月'],
        ['2017-4-27', '初二'],
        ['2017-4-28', '初三'],
        ['2017-4-29', '初四'],
        ['2017-4-30', '初五'],
        ['2017-5-1', '初六'],
        ['2017-5-2', '初七'],
        ['2017-5-3', '初八'],
        ['2017-5-4', '初九'],
        ['2017-5-5', '初十', '立夏'],
        ['2017-5-6', '十一'],
        ['2017-5-7', '十二'],
        ['2017-5-8', '十三'],
        ['2017-5-9', '十四'],
        ['2017-5-10', '十五'],
        ['2017-5-11', '十六'],
        ['2017-5-12', '十七'],
        ['2017-5-13', '十八'],
        ['2017-5-14', '十九'],
        ['2017-5-15', '二十'],
        ['2017-5-16', '廿一'],
        ['2017-5-17', '廿二'],
        ['2017-5-18', '廿三'],
        ['2017-5-19', '廿四'],
        ['2017-5-20', '廿五'],
        ['2017-5-21', '廿六', '小滿'],
        ['2017-5-22', '廿七'],
        ['2017-5-23', '廿八'],
        ['2017-5-24', '廿九'],
        ['2017-5-25', '三十'],
        ['2017-5-26', '五月'],
        ['2017-5-27', '初二'],
        ['2017-5-28', '初三'],
        ['2017-5-29', '初四'],
        ['2017-5-30', '初五'],
        ['2017-5-31', '初六'],
        ['2017-6-1', '初七'],
        ['2017-6-2', '初八'],
        ['2017-6-3', '初九'],
        ['2017-6-4', '初十'],
        ['2017-6-5', '十一', '芒種'],
        ['2017-6-6', '十二'],
        ['2017-6-7', '十三'],
        ['2017-6-8', '十四'],
        ['2017-6-9', '十五'],
        ['2017-6-10', '十六'],
        ['2017-6-11', '十七'],
        ['2017-6-12', '十八'],
        ['2017-6-13', '十九'],
        ['2017-6-14', '二十'],
        ['2017-6-15', '廿一'],
        ['2017-6-16', '廿二'],
        ['2017-6-17', '廿三'],
        ['2017-6-18', '廿四'],
        ['2017-6-19', '廿五'],
        ['2017-6-20', '廿六'],
        ['2017-6-21', '廿七', '夏至'],
        ['2017-6-22', '廿八'],
        ['2017-6-23', '廿九'],
        ['2017-6-24', '六月'],
        ['2017-6-25', '初二'],
        ['2017-6-26', '初三'],
        ['2017-6-27', '初四'],
        ['2017-6-28', '初五'],
        ['2017-6-29', '初六'],
        ['2017-6-30', '初七'],
        ['2017-7-1', '初八'],
        ['2017-7-2', '初九'],
        ['2017-7-3', '初十'],
        ['2017-7-4', '十一'],
        ['2017-7-5', '十二'],
        ['2017-7-6', '十三'],
        ['2017-7-7', '十四', '小暑'],
        ['2017-7-8', '十五'],
        ['2017-7-9', '十六'],
        ['2017-7-10', '十七'],
        ['2017-7-11', '十八'],
        ['2017-7-12', '十九'],
        ['2017-7-13', '二十'],
        ['2017-7-14', '廿一'],
        ['2017-7-15', '廿二'],
        ['2017-7-16', '廿三'],
        ['2017-7-17', '廿四'],
        ['2017-7-18', '廿五'],
        ['2017-7-19', '廿六'],
        ['2017-7-20', '廿七'],
        ['2017-7-21', '廿八'],
        ['2017-7-22', '廿九', '大暑'],
        ['2017-7-23', '閏六'],
        ['2017-7-24', '初二'],
        ['2017-7-25', '初三'],
        ['2017-7-26', '初四'],
        ['2017-7-27', '初五'],
        ['2017-7-28', '初六'],
        ['2017-7-29', '初七'],
        ['2017-7-30', '初八'],
        ['2017-7-31', '初九'],
        ['2017-8-1', '初十'],
        ['2017-8-2', '十一'],
        ['2017-8-3', '十二'],
        ['2017-8-4', '十三'],
        ['2017-8-5', '十四'],
        ['2017-8-6', '十五'],
        ['2017-8-7', '十六', '立秋'],
        ['2017-8-8', '十七'],
        ['2017-8-9', '十八'],
        ['2017-8-10', '十九'],
        ['2017-8-11', '二十'],
        ['2017-8-12', '廿一'],
        ['2017-8-13', '廿二'],
        ['2017-8-14', '廿三'],
        ['2017-8-15', '廿四'],
        ['2017-8-16', '廿五'],
        ['2017-8-17', '廿六'],
        ['2017-8-18', '廿七'],
        ['2017-8-19', '廿八'],
        ['2017-8-20', '廿九'],
        ['2017-8-21', '三十'],
        ['2017-8-22', '七月'],
        ['2017-8-23', '初二', '處暑'],
        ['2017-8-24', '初三'],
        ['2017-8-25', '初四'],
        ['2017-8-26', '初五'],
        ['2017-8-27', '初六'],
        ['2017-8-28', '初七'],
        ['2017-8-29', '初八'],
        ['2017-8-30', '初九'],
        ['2017-8-31', '初十'],
        ['2017-9-1', '十一'],
        ['2017-9-2', '十二'],
        ['2017-9-3', '十三'],
        ['2017-9-4', '十四'],
        ['2017-9-5', '十五'],
        ['2017-9-6', '十六'],
        ['2017-9-7', '十七', '白露'],
        ['2017-9-8', '十八'],
        ['2017-9-9', '十九'],
        ['2017-9-10', '二十'],
        ['2017-9-11', '廿一'],
        ['2017-9-12', '廿二'],
        ['2017-9-13', '廿三'],
        ['2017-9-14', '廿四'],
        ['2017-9-15', '廿五'],
        ['2017-9-16', '廿六'],
        ['2017-9-17', '廿七'],
        ['2017-9-18', '廿八'],
        ['2017-9-19', '廿九'],
        ['2017-9-20', '八月'],
        ['2017-9-21', '初二'],
        ['2017-9-22', '初三'],
        ['2017-9-23', '初四', '秋分'],
        ['2017-9-24', '初五'],
        ['2017-9-25', '初六'],
        ['2017-9-26', '初七'],
        ['2017-9-27', '初八'],
        ['2017-9-28', '初九'],
        ['2017-9-29', '初十'],
        ['2017-9-30', '十一'],
        ['2017-10-1', '十二'],
        ['2017-10-2', '十三'],
        ['2017-10-3', '十四'],
        ['2017-10-4', '十五'],
        ['2017-10-5', '十六'],
        ['2017-10-6', '十七'],
        ['2017-10-7', '十八'],
        ['2017-10-8', '十九', '寒露'],
        ['2017-10-9', '二十'],
        ['2017-10-10', '廿一'],
        ['2017-10-11', '廿二'],
        ['2017-10-12', '廿三'],
        ['2017-10-13', '廿四'],
        ['2017-10-14', '廿五'],
        ['2017-10-15', '廿六'],
        ['2017-10-16', '廿七'],
        ['2017-10-17', '廿八'],
        ['2017-10-18', '廿九'],
        ['2017-10-19', '三十'],
        ['2017-10-20', '九月'],
        ['2017-10-21', '初二'],
        ['2017-10-22', '初三'],
        ['2017-10-23', '初四', '霜降'],
        ['2017-10-24', '初五'],
        ['2017-10-25', '初六'],
        ['2017-10-26', '初七'],
        ['2017-10-27', '初八'],
        ['2017-10-28', '初九'],
        ['2017-10-29', '初十'],
        ['2017-10-30', '十一'],
        ['2017-10-31', '十二'],
        ['2017-11-1', '十三'],
        ['2017-11-2', '十四'],
        ['2017-11-3', '十五'],
        ['2017-11-4', '十六'],
        ['2017-11-5', '十七'],
        ['2017-11-6', '十八'],
        ['2017-11-7', '十九', '立冬'],
        ['2017-11-8', '二十'],
        ['2017-11-9', '廿一'],
        ['2017-11-10', '廿二'],
        ['2017-11-11', '廿三'],
        ['2017-11-12', '廿四'],
        ['2017-11-13', '廿五'],
        ['2017-11-14', '廿六'],
        ['2017-11-15', '廿七'],
        ['2017-11-16', '廿八'],
        ['2017-11-17', '廿九'],
        ['2017-11-18', '十月'],
        ['2017-11-19', '初二'],
        ['2017-11-20', '初三'],
        ['2017-11-21', '初四'],
        ['2017-11-22', '初五', '小雪'],
        ['2017-11-23', '初六'],
        ['2017-11-24', '初七'],
        ['2017-11-25', '初八'],
        ['2017-11-26', '初九'],
        ['2017-11-27', '初十'],
        ['2017-11-28', '十一'],
        ['2017-11-29', '十二'],
        ['2017-11-30', '十三'],
        ['2017-12-1', '十四'],
        ['2017-12-2', '十五'],
        ['2017-12-3', '十六'],
        ['2017-12-4', '十七'],
        ['2017-12-5', '十八'],
        ['2017-12-6', '十九'],
        ['2017-12-7', '二十', '大雪'],
        ['2017-12-8', '廿一'],
        ['2017-12-9', '廿二'],
        ['2017-12-10', '廿三'],
        ['2017-12-11', '廿四'],
        ['2017-12-12', '廿五'],
        ['2017-12-13', '廿六'],
        ['2017-12-14', '廿七'],
        ['2017-12-15', '廿八'],
        ['2017-12-16', '廿九'],
        ['2017-12-17', '三十'],
        ['2017-12-18', '十一月'],
        ['2017-12-19', '初二'],
        ['2017-12-20', '初三'],
        ['2017-12-21', '初四'],
        ['2017-12-22', '初五', '冬至'],
        ['2017-12-23', '初六'],
        ['2017-12-24', '初七'],
        ['2017-12-25', '初八'],
        ['2017-12-26', '初九'],
        ['2017-12-27', '初十'],
        ['2017-12-28', '十一'],
        ['2017-12-29', '十二'],
        ['2017-12-30', '十三'],
        ['2017-12-31', '十四']
      ];
      let heatmapData = [];
      let lunarData = [];
      for (let i = 0; i < dateList.length; i++) {
        heatmapData.push([dateList[i][0], Math.random() * 300]);
        lunarData.push([dateList[i][0], 1, dateList[i][1], dateList[i][2]]);
      }
     const option = {
        tooltip: {
          formatter: function (params) {
            return '降雨量: ' + params.value[1].toFixed(2);
          }
        },
        visualMap: {
          show: false,
          min: 0,
          max: 300,
          calculable: true,
          seriesIndex: [2],
          orient: 'horizontal',
          left: 'center',
          bottom: 20,
          inRange: {
            color: ['#e0ffff', '#006edd'],
            opacity: 0.3
          },
          controller: {
            inRange: {
              opacity: 0.5
            }
          }
        },
        calendar: [
          {
            left: 'center',
            top: 'middle',
            cellSize: [70, 70],
            yearLabel: { show: false },
            orient: 'vertical',
            dayLabel: {
              firstDay: 1,
              nameMap: 'cn'
            },
            monthLabel: {
              show: false
            },
            range: '2017-03'
          }
        ],
        series: [
          {
            type: 'scatter',
            coordinateSystem: 'calendar',
            symbolSize: 1,
            label: {
              show: true,
              formatter: function (params) {
                var d = echarts.number.parseDate(params.value[0]);
                return d.getDate() + '\n\n' + params.value[2] + '\n\n';
              },
              color: '#000'
            },
            data: lunarData
          },
          {
            type: 'scatter',
            coordinateSystem: 'calendar',
            symbolSize: 1,
            label: {
              show: true,
              formatter: function (params) {
                return '\n\n\n' + (params.value[3] || '');
              },
              fontSize: 14,
              fontWeight: 700,
              color: '#a00'
            },
            data: lunarData
          },
          {
            name: '降雨量',
            type: 'heatmap',
            coordinateSystem: 'calendar',
            data: heatmapData
          }
        ]
      };
      (<any>global.homeChartFour).setOption(option);
      (<any>state.myCharts).push(global.homeChartFour);
    };
    // 批量设置 echarts resize
    const initEchartsResizeFun = () => {
      nextTick(() => {
        for (let i = 0; i < state.myCharts.length; i++) {
          setTimeout(() => {
            (<any>state.myCharts[i]).resize();
          }, i * 1000);
        }
      });
    };
    // 批量设置 echarts resize
    const initEchartsResize = () => {
      window.addEventListener('resize', initEchartsResizeFun);
    };
    // 页面加载时
    onMounted(() => {
      initEchartsResize();
    });
    // 由于页面缓存原因，keep-alive
    onActivated(() => {
      initEchartsResizeFun();
    });
    // 监听 vuex 中的 tagsview 开启全屏变化，重新 resize 图表，防止不出现/大小不变等
    watch(
        () => store.state.tagsViewRoutes.isTagsViewCurrenFull,
        () => {
          initEchartsResizeFun();
        }
    );
    // 监听 vuex 中是否开启深色主题
    watch(
        () => store.state.themeConfig.themeConfig.isIsDark,
        (isIsDark) => {
          nextTick(() => {
            state.charts.theme = isIsDark ? 'dark' : '';
            state.charts.bgColor = isIsDark ? 'transparent' : '';
            state.charts.color = isIsDark ? '#dadada' : '#303133';
            setTimeout(() => {
              initLineChart();
            }, 500);
            setTimeout(() => {
              initWorldcouldChart();
            }, 700);
            setTimeout(() => {
              initBarChart();
            }, 1000);
            setTimeout(() => {
              initBarChart1();
            }, 1000);

          });
        },
        {
          deep: true,
          immediate: true,
        }
    );
    return {
      homeLineRef,
      homePieRef,
      homeBarRef,
      homeBar1Ref,
      ...toRefs(state),
    };
  },
});
</script>

<style scoped lang="scss">
$homeNavLengh: 8;
.home-container {
  overflow: hidden;
  .home-card-one,
  .home-card-two,
  .home-card-three {
    .home-card-item {
      width: 100%;
      height: 130px;
      border-radius: 4px;
      transition: all ease 0.3s;
      padding: 20px;
      overflow: hidden;
      background: var(--el-color-white);
      color: var(--el-text-color-primary);
      border: 1px solid var(--next-border-color-light);
      &:hover {
        box-shadow: 0 2px 12px var(--next-color-dark-hover);
        transition: all ease 0.3s;
      }
      &-icon {
        width: 70px;
        height: 70px;
        border-radius: 100%;
        flex-shrink: 1;
        i {
          color: var(--el-text-color-placeholder);
        }
      }
      &-title {
        font-size: 15px;
        font-weight: bold;
        height: 30px;
      }
    }
  }
  .home-card-one {
    @for $i from 0 through 3 {
      .home-one-animation#{$i} {
        opacity: 0;
        animation-name: error-num;
        animation-duration: 0.5s;
        animation-fill-mode: forwards;
        animation-delay: calc($i/10) + s;
      }
    }
  }
  .home-card-two,
  .home-card-three {
    .home-card-item {
      height: 400px;
      width: 100%;
      overflow: hidden;
      .home-monitor {
        height: 100%;
        .flex-warp-item {
          width: 25%;
          height: 111px;
          display: flex;
          .flex-warp-item-box {
            margin: auto;
            text-align: center;
            color: var(--el-text-color-primary);
            display: flex;
            border-radius: 5px;
            background: var(--next-bg-color);
            cursor: pointer;
            transition: all 0.3s ease;
            &:hover {
              background: var(--el-color-primary-light-9);
              transition: all 0.3s ease;
            }
          }
          @for $i from 0 through $homeNavLengh {
            .home-animation#{$i} {
              opacity: 0;
              animation-name: error-num;
              animation-duration: 0.5s;
              animation-fill-mode: forwards;
              animation-delay: calc($i/10) + s;
            }
          }
        }
      }
    }
  }
}
</style>
